import { reactive } from 'vue'

function createUserList() {
  return [
    {
      userId: 1,
      username: 'admin',
      password: '111111',
      desc: '平台管理员',
      roles: ['平台管理员'],
      buttons: ['cuser.detail'],
      routes: [
        'User',
        'Acl',
        'Role',
        'Permission',
        'demoAcl',
        'demoUser',
        'demoRole',
        'demoPermission',
      ],
      token: 'Admin Token',
    },
    {
      userId: 2,
      username: 'user',
      password: '111111',
      desc: '普通用户',
      roles: ['普通用户'],
      buttons: ['cuser.detail', 'cuser.user'],
      routes: ['Acl', 'User', 'demoAcl', 'demoUser'],
      token: 'user Token',
    },
  ]
}

export default [
  {
    url: '/api/user/login',
    method: 'post',
    response: ({ body }) => {
      const { username, password } = body
      const checkUser = createUserList().find(
        (item) => item.username === username && item.password === password,
      )
      if (!checkUser) {
        return { code: 201, data: { message: '账号或者密码不正确' } }
      }
      const { token, routes } = checkUser
      return { code: 200, data: { token, routes, username } }
    },
  },
  {
    url: '/api/routers',
    method: 'post',
    response: ({ body }) => {
      const { username } = body
      const checkUser = createUserList().find(
        (item) => item.username === username,
      )
      if (!checkUser) {
        return { code: 201, data: { message: '账号或者密码不正确' } }
      }
      const { token, routes } = checkUser
      return { code: 200, data: { routes } }
    },
  },
]
